import axios from 'axios'
import { Toast } from 'vant'

// 创建axios实例
const service = axios.create({
  baseURL: 'http://www.xiongmaoyouxuan.com',
  timeout: 5000
})
// 请求拦截
service.interceptors.request.use(config => {
  Toast.loading({
    message: '加载中...',
    forbidClick: true,
    duration: 0
  })
  config.headers = {
  }
  return config
})
// 响应拦截
service.interceptors.response.use(config => {
  Toast.clear()
  if (config.status >= 200 && config.status < 300) {
    if (config.data.code === 200) {
      return config.data.data
    }
    return Promise.reject(config.data)
  }
  return Promise.reject(config)
})
export default service
